//
//  SettingViewController.m
//  YSSmartHome
//
//  Created by yanghao on 2016/10/20.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "SettingViewController.h"
#import "GatewayManageController.h"
#import "UIView+Frame.h"
#import "GlobalConst.h"
@interface SettingViewController ()
@property (weak, nonatomic) IBOutlet UITableViewCell *shockSwichCell;


@end

@implementation SettingViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.yh_y = 10;
    UISwitch *shockSwitch = [[UISwitch alloc]init];
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
    BOOL isOpen =  [userDefaults boolForKey:kZTShockSwitchIsOpen];
    [shockSwitch setOn:isOpen];
    [shockSwitch addTarget:self action:@selector(shockSwichChange:) forControlEvents:UIControlEventValueChanged];
    self.shockSwichCell.accessoryView = shockSwitch;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)shockSwichChange:(UISwitch*)shockSwitch
{
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:shockSwitch.isOn forKey:@"kZTShockSwitchIsOpen"];
    [userDefaults synchronize];
}
+ (instancetype)createSettingController
{
    UIStoryboard *currentBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    return  [currentBoard instantiateViewControllerWithIdentifier:@"SettingView"];
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        GatewayManageController *gatewayManageVc = [[GatewayManageController alloc]init];
        [self.navigationController pushViewController:gatewayManageVc animated:YES];
    }
}

@end
